package com.sais.manage.boot.daily.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sais.common.entity.Result;
import com.sais.manage.boot.daily.dto.VisitorDTO;
import com.sais.manage.boot.daily.dto.VisitorSaveDTO;
import com.sais.manage.boot.daily.dto.VisitorSearchDTO;
import com.sais.manage.boot.daily.service.IVisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 宿舍管理系统-来访登记 controller 类
 *
 * @author zwp
 * @date 2020/2/2
 **/
@Api(tags = "来访登记管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/daily/visitor")
public class VisitorController {

    @Resource
    private IVisitorService visitorService;

    @ApiOperation("来访登记 保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveVisitor(@RequestBody VisitorSaveDTO visitorSaveDTO) {
        visitorService.saveVisitor(visitorSaveDTO);
        return new Result();
    }

    @ApiOperation("来访登记 删除")
    @RequestMapping(value = "/delete/{visitorId}", method = RequestMethod.GET)
    public Result deleteVisitor(@PathVariable("visitorId") String visitorId) {
        visitorService.deleteVisitor(visitorId);
        return new Result();
    }

    @ApiOperation("根据id 查询 来访登记")
    @RequestMapping(value = "/select/{visitorId}", method = RequestMethod.GET)
    public Result selectVisitor(@PathVariable("visitorId") String visitorId) {
        VisitorDTO visitor = visitorService.selectVisitor(visitorId);
        return new Result().data("visitor", visitor);
    }

    @ApiOperation("分页条件 查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listVisitor(@RequestParam(defaultValue = "1") Integer current,
                              @RequestParam(defaultValue = "30") Integer size,
                              VisitorSearchDTO searchDTO) {
        Page<VisitorDTO> page = visitorService.listVisitor(current, size, searchDTO);
        return new Result().data("visitors", page);
    }


}
